angular.module('imsApp').controller('copyScreenAddModalController', ['$scope','$state', 'appId','$uibModalInstance','copyScreenManager',
    function ($scope,$state, appId,$uibModalInstance,copyScreenManager) {
     $scope.userInfo=JSON.parse(localStorage.getItem("userInfo"))
    $scope.imagesUrl=[];
    $scope.ok = function () {
        saveCopyScreenData();
    };

    $scope.cancel = function () {
        $uibModalInstance.close("cancel");
    };
    $scope.removeFile=function (item) {
        if(item.successUrl){
            $scope.imagesUrl.splice($scope.imagesUrl.indexOf(item.successUrl),1)
        }

    }


    var saveCopyScreenData=function () {
        if(!$scope.imagesUrl.length){
           return false;
        }
        copyScreenManager.saveCopyScreen($state.params.campaignId,appId,$scope.imagesUrl).then(function (result) {
            if(result.data.c=='s'){
                $uibModalInstance.close("ok");
            }else {

                $uibModalInstance.close("error");
            }
        })
    };

    //Listen FileNums
    $scope.$watch("uploaderImage.queue.length", function (newValue, oldValue, scope) {
        if (newValue.keywords == oldValue.keywords) {
            $scope.fileNums = $scope.uploaderImage.queue.length;
        }
    }, true);

    //获取文件
    var image = copyScreenManager.getImage($scope);

    //提交图片
    $scope.submitImage = function () {
        copyScreenManager.uploadFile($scope, image);
    };




}]);

